(ns clj.ex2)
(import '(com.aligotec Address User))


(defn test2 [& args]
  (println "Playing in first test2 " args)
  
  (defn long-process [time-to-sleep]
    (Thread/sleep time-to-sleep)
    (* time-to-sleep 10))
  
  (defn long-run []
  (let [x1 (future (long-process 5001))
        x2 (future (long-process 5011))
        x3 (future (long-process 4990))
        t (+ @x1 @x2 @x3)]
    t))
    
  (time (long-run))
  
  (println "---")
  
  (def value (promise))
  
  (defn wait-thread [tsleep]
    (println "wait s")
    (Thread/sleep tsleep)
    (println "wait e")
    (deliver value (* 1.3 tsleep)))
  
  (defn use-value []
    (println "use-value-pre")
    (let [v (/ @value 1.3)]
      (println "use value" v)
      v))
  
  (defn l-paral []
  (let [t1 (future (wait-thread 3000))
        t2 (future (use-value))]
   @t1
    (println "pre-use")
    (println "use-thread" @t2 @t1)))
  
  (time (l-paral))
  
  "test2 finished")